<template>
	<view class="profile">
		<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">个人信息</block>
		</cu-custom>
		<view class="cu-form-group">
			<view class="title">UID</view>
			<input :value="userInfo.id" disabled=""></input>
		</view>
		<view class="cu-form-group">
			<view class="title">昵称</view>
			<input v-model="form.nickname"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">手机号</view>
			<input v-model="form.change_mobile"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">积分</view>
			<input :value="userInfo.score" disabled=""></input>
		</view>
		
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-gradual-orange margin-tb-sm lg" @tap="profile">完善资料</button>
		</view>
		
	
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	import user from '@/api/user.js';
	export default {
		data() {
			return {
				form:{
					nickname:'',
					change_mobile:""
				}
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		onLoad(){
			this.form.nickname = this.userInfo.nickname
			this.form.change_mobile = this.userInfo.mobile
		},
		methods: {
			profile(){
				
				user.profile(this.form).then(res => {
					uni.hideLoading();
					return this.toast(res.msg)
					// if (res.code !== 1) {
					// 	return this.toast(res.msg)
					// }
					// if (res.code === 1) {
					// 	// this.$store.commit('logout');
					// 	uni.navigateBack();
					// }
				})
			},
			logout() {
				// 登录账号
				user.logout().then(res => {
					uni.hideLoading();
					if (res.code !== 1) {
						return this.toast(res.msg)
					}
					if (res.code === 1) {
						this.$store.commit('logout');
						uni.navigateBack();
					}
				})
			},
		
		}
	}
</script>

<style>

</style>
